import React from 'react'
import PropTypes from 'prop-types'
import { TabBar } from 'antd-mobile';
import {withRouter,Redirect} from 'react-router-dom'
import {connect} from 'react-redux'
@withRouter
@connect(
    state=>state.chat
)
class NavLinkBar extends React.Component{
    static propTypes={
        data:PropTypes.array.isRequired
    }
    constructor(props){
        super(props)
        this.state={
            path:''
        }
    }
    render(){
        const navList=this.props.data.filter(v=>!v.hide)
        const {pathname}=this.props.location
        // console.log('====================================');
        // console.log(this.props);
        // console.log('====================================');

        return (
            // <div>123</div>
            <div>
                {this.state.path&&this.state.path!=pathname?<Redirect to={this.state.path} />:null}

            <TabBar>
                {navList.map(v=>(
                    
                    <TabBar.Item
                        badge={v.path=='/msg'?this.props.unread:''}
                        title={v.title}
                        key={v.path}
                        icon={{uri:require(`./img/${v.icon}.png`)}}
                        selectedIcon={{uri:require(`./img/${v.icon}-active.png`)}}
                        selected={pathname==v.path}
                        onPress={()=>{
                            console.log(`./img/${v.icon}-active.png`)
                            // return (<Redirect to={v.path} />);
                            // this.props.history.push(v.path)
                            this.setState({
                                path:v.path
                            },()=>{
                                // console.log(this.state.path);
                            })
                            
                            
                        }}
                    >
                    </TabBar.Item>
                ))}
            </TabBar>
            </div>
        )
    }
}
export default NavLinkBar